#include "MSSQLConnection.h"

namespace SQLDoc
{
	const QString MSSQLConnection::SELECT_DATABASES_QUERY("select [database_id], [name] from sys.databases");

	MSSQLConnection::MSSQLConnection(void)
		: DBConnection()
	{ }

	MSSQLConnection::~MSSQLConnection(void)
	{ }

	void MSSQLConnection::fillDatabases()
	{
		DBConnection::fillDatabases();

		QSqlDatabase db = QSqlDatabase::database(this->connectionName());

		QSqlQuery query(db);
		query.setForwardOnly(true);
		query.exec(SELECT_DATABASES_QUERY);

		while (query.next())
		{
			MSSQLDb* t = new MSSQLDb();
			t->setId(query.value(0).toInt());
			t->setName(query.value(1).toString());
			m_databases.append(t);
		}
	}
}